package com.hospital.new_yygh.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hospital.new_yygh.service.AdminService;
import com.hospital.new_yygh.entity.user.Admin;
import com.hospital.new_yygh.entity.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理员")
@RestController
@RequestMapping("/admin")
@CrossOrigin
public class AdminController {

    //注入service
    @Autowired
    private AdminService adminService;

    //管理员登录接口
    @ApiOperation(value = "管理员登录")
    @PostMapping("/adminLogin/{username}/{password}")
    public Result adminLogin(@PathVariable String username,
                             @PathVariable String password){
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        Admin admin = adminService.getOne(wrapper);
        //查询管理员是否存在
        if (admin != null && admin.getPassword().equals(password)){
            //管理员存在且密码正确
            return Result.ok(admin);
        }else{
            return Result.fail();
        }
    }


}
